public with sharing class InstrumentFollowController {

	public String msg {private set; get;}
	public Boolean isSuc {private set; get;}
	public Boolean isErr {private set; get;}
	public String backId {private set; get;}

	public String dataJson {private set; get;}
	public String saveJson {set; get;}

	public boolean isTrans{private set; get;}
	public boolean isSync{private set; get;}
	public boolean canEdit{get;private set;}

    public boolean isAccountSource{get;private set;}
    private Account  acc;
	public Set<String> hhdhs = new Set<String>();



    public InstrumentFollowController() {
        backId = System.currentPageReference().getParameters().get('id');
        isSync =System.currentPageReference().getParameters().get('sync') != null ;
        isTrans = false ;
        canEdit = true ;
        isAccountSource = false;
        acc = new Account();
    }

    public  void init (){
    	try{
    		if(backId == null) throw new DmlException('页面打开错误!');
    		

             Map<String,Object>  dataMap = new Map<String,Object>();
    		if(Id.valueOf(backId).getSobjectType() == InstrumentDeliveryApplication__c.SObjectType ){
                InstrumentDeliveryApplication__c ida = [select Id,RelatedNCDocuments__c,RecordType.DeveloperName,NC__c,ToNC__c ,InvoicingCustomers__c from  InstrumentDeliveryApplication__c where Id=:backId];
                isTrans = ida.RecordType.DeveloperName == 'DeliveryAfterReturn';
                 isAccountSource = isTrans && ida.InvoicingCustomers__c != null;
                if(isSync){
                    return;
                }
                acc = [select Id ,AccountNumber from Account where Id =:ida.InvoicingCustomers__c ] ;

                if(isTrans){

                   
                    canEdit  = !ida.NC__c && !ida.ToNC__c ;
                    getHhdhs(ida.RelatedNCDocuments__c);
                    dataMap.put('data', getDetails());
                    dataMap.put('search', getDataFromNc());

                }else{ 

                    getHhdhs(backId);
                    List<ProductBean> tmp = getDataFromNc();
                    if(tmp.isEmpty()) throw new DmlException('该仪器发货申请单在NC没有还回的仪器明细!'); 
                    
                    dataMap.put('search', tmp);
                    dataMap.put('data', new List<ProductBean>());

                } 

                

            }else if(Id.valueOf(backId).getSobjectType() == Account.SObjectType ){
                isAccountSource = true ;
                acc = [select Id ,AccountNumber from Account where Id =:backId ] ;
                getHhdhs(backId);

                List<ProductBean> tmp = getDataFromNc();
                if(tmp.isEmpty()) throw new DmlException('该仪客户在NC没有还回的仪器明细!'); 
                dataMap.put('search', tmp);
                dataMap.put('data', new List<ProductBean>());


            }
    		dataJson = EncodingUtil.urlEncode(JSON.serialize(dataMap), 'utf-8');

    		
    	}catch(Exception e ){
    		isErr = true;
    		ApexPages.addMessage( new ApexPages.Message(ApexPages.Severity.ERROR ,e.getMessage()+e.getStackTraceString()));

    	}

    }
    public void setNil(){
    	saveJson = '';
    	dataJson = '[]';
    }

    public void getHhdhs(String mId ){

    	for( InstrumentDeliverynDetails__c idd :[select Id ,ReturnNo__c from InstrumentDeliverynDetails__c  where ReturnToMainTable__r.RelatedNCDocuments__c =:mId or ReturnToMainTable__r.InvoicingCustomers__c =:mId ]){
    		
    		if(idd.ReturnNo__c != null )hhdhs.add(idd.ReturnNo__c );
    	}

    }

    //从NC获取数据
    private List<ProductBean>  getDataFromNc(){
        String url = Label.NCExchangeInterface;//'https://esb.maccura.com:9088/api/Domain/univer/dbbus/search';
        
        Map<String, String >dataMap = new Map<String,String>();
        //测试 NC42_15 NC_JC_FOLLOW_TEST NC_ACCOUNTJC_FOLLOW_TEST
        dataMap.put('source','NC');    
     
        dataMap.put('tag',isAccountSource ? 'NC_ACCOUNTJC_FOLLOW': 'NC_JC_FOLLOW' );
        
        dataMap.put('sfid',isAccountSource ? acc.AccountNumber :  Id.valueOf(backId));//a3G0k000001BV32EAG


        System.debug(JSON.serialize(dataMap));        
        //请求
        HttpRequest req = new HttpRequest();
        req.setMethod('POST');
        req.setHeader('Content-Type','application/x-www-form-urlencoded ; charset=utf-8');
        req.setEndpoint(url+'?data='+JSON.serialize(dataMap));
        HttpResponse res = Utils.postRequest(req, 2);
      ///返回结果处理
        if (res.getStatusCode() == 200) {
            System.debug(res.getBody());
            Map<String,Object> r = null;
              //如果是测试
                if(Test.isRunningTest()){
                  Map<String,Object>  resBody= new Map<String,Object>();
                  resBody.put('code','0');
                  resBody.put('result','{"result":[{"B_RECVMATERWHID":"1001C210000000000CK2","H_PK_DEFDOC18":"0001A0100000000NHEM9","H_PK_ORG_ID":"1001C2100000000004YH","HHDH":"CH012101280002","SF_BID":"a3J0k0000042OxLEAU  ","H_UNITCODE":"MKSW","H_CDPTID":"1001C210000000001L39","H_CBIZID":"0001A0100000000BGG5H","SF_HID":"a3G0k000001BV2xEAG  ","H_VBILLCODE":"SA012101280009","H_VUSERDEF5":"11","B_CINVBASID":"0001A0100000003VWA0H","B_INVCODE":"100020100003","H_PK_DEFDOC7":"0001C2100000000013YZ","B_CUNITID":"0001C210000000000JZ0","B_VBATCHCODE":null,"H_PK_DEFDOC3":"0001Y01000000002RAW6","H_PK_DEFDOC1":null,"B_SAPPLY_BID":"1001AA100000007JT34C","H_SAPPLY_HID":"1001AA100000007JT34B","H_PK_DEFDOC8":"0001A0100000000JZQU6","H_PK_DEFDOC9":"0001A01000000008VX54","HHSL":"2","H_VNOTE":null,"H_CUSTCODE":"300657","B_INVNAME":"全自动化学发光免疫分析仪","H_PK_CORP":"1001","B_CINVENTORYID":"0001A0100000003VWA0K"}],"code":"0","msg":"success"}');
                    r =  resBody;
                }else{
                  r= (Map<String,Object> ) JSON.deserializeUntyped(res.getBody());
                }
          	if(r.get('code') == 0 || r.get('code') == '0'){
                Map<String,Object> rs = (Map<String,Object>) JSON.deserializeUntyped(((String)r.get('result')));
	             if( (rs.get('code') == 0 || rs.get('code') == '0' ) ){
	                    
	             		List<Object> datas = (List<Object>)rs.get('result');
	             		List<ProductBean> tmp = new List<ProductBean>();

	             		System.debug(hhdhs);

	             		for(Object o : datas){
	             			Map<String,Object> m = (Map<String,Object>)o ; 
	             			//String sfbid = DataUtil.getStringValue(m.get('SF_BID'));
	             			ProductBean p = new ProductBean(m);
	             			if(hhdhs.contains(p.hhdh))continue;
	             			tmp.add(p);

	             		}

	             		return tmp;




	             }else{
	                    throw new DmlException((String )rs.get('msg'));
	             }

            }else{
                throw new DmlException((String )r.get('msg'));

            }

        }else{
          	throw new DmlException(res.getBody());
        } 
        
    }

    public void save(){
    	msg = '';
    	try{
    		List<Object> datas = (List<Object>) JSON.deserializeUntyped(EncodingUtil.urlDecode(saveJson, 'utf-8'));
    		if(datas.isEmpty())throw new DmlException('没有数据');

    		List<InstrumentDeliverynDetails__c> details = new List<InstrumentDeliverynDetails__c>();

    		for(Object o : datas){
    			Map<String,Object> m = (Map<String,Object>)o ;
    			InstrumentDeliverynDetails__c idd = new InstrumentDeliverynDetails__c();
    			idd.ReturnNo__c = DataUtil.getStringValue(m.get('hhdh'));
    			idd.ReturnQuantity__c = DataUtil.getDecimalValue(m.get('sl'));
    			idd.ResaleQuantity__c = DataUtil.getDecimalValue(m.get('sl_sale'));
    			idd.FreeQuantity__c = DataUtil.getDecimalValue(m.get('sl_ck'));
    			idd.NcPrice__c =  DataUtil.getDecimalValue(m.get('price'));
    			idd.SF_ID__c = DataUtil.getStringValue(m.get('sf_bid'));
    			idd.WarehouseNo__c =  DataUtil.getStringValue(m.get('ckdh'));
    			idd.Code__c =  DataUtil.getStringValue(m.get('nccode'));
    			idd.RowData__c = JSON.serialize(m);
    			idd.Name = DataUtil.getStringValue(m.get('name'));
                idd.ProductName__c = DataUtil.getStringValue(m.get('name'));

    			details.add(idd);


    		}

    		InstrumentDeliveryApplication__c ida = new InstrumentDeliveryApplication__c();

    		ida.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('DeliveryAfterReturn', 'InstrumentDeliveryApplication__c');
    		
            if(isAccountSource ){
            }else{
                ida.RelatedNCDocuments__c = backId;
              
            }
              ida.InvoicingCustomers__c  = acc.Id ;

            if(isTrans){
                ida.Id = backId;
            }

    		Savepoint sp = Database.setSavepoint();
    		try{

    			upsert  ida;
    			for (InstrumentDeliverynDetails__c idd  : details) {
    				idd.ReturnToMainTable__c = ida.Id;
    			}
                delete [select Id from InstrumentDeliverynDetails__c where ReturnToMainTable__c  = : ida.Id ];
    			insert details;

    			isSuc = true;
    			msg = '保存成功!';
    			backId = ida.Id;
    		}catch(Exception e ){

    			Database.rollback(sp);
    			throw e;
    		}

    	}catch(Exception e ){
    		msg = '保存失败!'+e.getMessage();
    	}

    }

    public List<ProductBean>  getDetails(){
		List<ProductBean> tmp = new List<ProductBean>();
	  	for(InstrumentDeliverynDetails__c idd : [select Id ,Name,ReturnNo__c ,Code__c,ReturnQuantity__c,ResaleQuantity__c, FreeQuantity__c,NcPrice__c,SF_ID__c ,WarehouseNo__c ,RowData__c from InstrumentDeliverynDetails__c where ReturnToMainTable__c =:backId] ){
	  		ProductBean p = new ProductBean(idd);
	  		tmp.add(p);
	  	}
	  	return tmp;
	    
    }
    //保存: 保存为转销售报价单 保存为:转其他出库/材料出库的出库单
    public void sync(){
    		msg = '';
    	  	InstrumentDeliveryApplication__c ida = [select Id ,NC__c ,RelatedNCDocuments__r.OwnerId  ,ResultMsg__c ,ToNC__c	 , ResultMsg2__c from InstrumentDeliveryApplication__c where Id =:backId];

    	try {
    	  	List<Object> tmp = new List<Object>();

            //1.销售员
            
            String userId = isAccountSource ? UserInfo.getUserId() :ida.RelatedNCDocuments__r.OwnerId;
    	  	User saler = [select Id,Name ,Manager.Name  from User where Id=:userId];

    	  	List<InstrumentDeliverynDetails__c> iddlist = [select Id ,Name,ReturnNo__c ,Code__c,ReturnQuantity__c,ResaleQuantity__c, FreeQuantity__c,NcPrice__c,SF_ID__c ,WarehouseNo__c ,RowData__c from InstrumentDeliverynDetails__c where ReturnToMainTable__c  =:backId];
	    	 Map<String,String> companyMap = ImportObject.getPicklistValues('Opportunity', 'Corpcode__c', true);
         	 Map<String,String> salesMap = ImportObject.getPicklistValues('PriceList__c', 'SalesCode__c', false);
    	  	List<ContractWebService.ConProductArgs> cpList = new List<ContractWebService.ConProductArgs>();
    	  	String companyCode = null;
    	  	for(InstrumentDeliverynDetails__c idd : iddlist ){
    	  		ProductBean p = new ProductBean(idd);
    	  		if(companyCode == null )companyCode = p.unitcode;
    	  		CKBean cb = new CKBean(p);
    	  		CKMBean cbm = new CKMBean(p);
                if(isAccountSource)cb.sf_hid = ida.Id;
                if(isAccountSource)cbm.sf_hid = ida.Id;

                if(isAccountSource)cb.sf_bid = idd.Id;
                if(isAccountSource)cbm.sf_bid = idd.Id;

                if(idd.FreeQuantity__c > 0 ){
                    if(companyCode == 'MKSW' ){
                        tmp.add(cb);
                    }else{
                        tmp.add(cbm);
                    }
                }

                
    	  		

    	  		if(idd.ResaleQuantity__c > 0 ){

                    

    	  			ContractWebService.ConProductArgs cp = new ContractWebService.ConProductArgs();
    	  			cp.corpcode = p.unitcode;
	                cp.custcode = p.custcode;
	                cp.vsalestrucode = salesMap.get(companyMap.get(p.unitcode ));
	                cp.created_by  = UserInfo.getName();
	                cp.sub_corp_manager = saler.Manager.Name;
	                //cp.csourcecode = '';
	                cp.ts  = System.now().format('yyyy-MM-dd HH:mm:ss');
	                cp.csalequotationid =ida.Id;
	                cp.csalequotation_bid =idd.Id ;
	                
	                cp.cemployeecode = saler.Name ; //所有者
	                cp.invcode =p.nccode; //产品的NCCode__c
	                cp.dreceiptdate  = Utils.date2string(Date.valueOf(System.now()));//报价日期

	                 cp.noriginalcurtaxprice = String.valueof(idd.NcPrice__c); 
	               
	                cp.nitemdiscountrate = '100';//默认100
	                cp.nnumber = String.valueof(idd.ResaleQuantity__c);
	                cp.opertype = '1'; //操作类型   1=新增  2=修改  3=删除
	                cp.quotetype = '1'; //报价类型   1=报价  2=调价
	               
	                cp.currtypename = '人民币';
	               // cpa.addCustomer =cp.Contract__r.TerminalCustomer__r.NCICCode__c;
	                cpList.add(cp);

    	  		}
    	  	}

    	  	if(!ida.NC__c && !tmp.isEmpty()){


    	  	
	    	  	Map<String,Object> dataMap = new Map<String,Object>();


	    	  	dataMap.put('data', tmp);


	    	   String data = JSON.serialize(dataMap);

	    	   String url = companyCode == 'MKSW' ?  Label.NCOtherInterface : Label.NCMaterialInterface ;

	            HttpRequest req = new HttpRequest();
	            req.setMethod('POST');
	            req.setBody(data);
	            System.debug(JSON.serialize(data));
	            req.setHeader('Content-Type','text/plain');
	            //req.setHeader('Content-Type','application/x-www-form-urlencoded ; charset=utf-8');
	            req.setEndpoint(url);
	            HttpResponse res = Utils.postRequest(req, 1);
	             ///返回结果处理
	            if (res.getStatusCode() == 200) {
	                System.debug(res.getBody());
	                Map<String,Object> r = null;
	                  //如果是测试
	                    if(Test.isRunningTest()){
	                        Map<String,Object>  resBody= new Map<String,Object>();
	                        resBody.put('code','0');
	                        resBody.put('result','{\"result_msg\":\"UPT40088-000001\",\"result\":1}');
	                        r =  resBody;
	                    }else{
	                        r= (Map<String,Object> ) JSON.deserializeUntyped(res.getBody());
	                    }
	              if(r.get('code') == 0 || r.get('code') == '0'){
	                    Map<String,Object> rs = (Map<String,Object>) JSON.deserializeUntyped(((String)r.get('result')));
	                    
	                  if( (rs.get('result') == 1 || rs.get('result') == '1' ) ){
	                        
	                       	ida.NC__c = true ;
	                        ida.ResultMsg__c = String.valueOf(r.get('result'));

	                   }else{
	                        throw new DmlException('同步出库单据失败 : '+rs.get('result_msg'));
	                   }

	                }else{

	                   throw new DmlException('同步出库单据失败 : '+String.valueOf(r.get('msg')));
	                }

	            }else{
	                throw new DmlException('同步出库单据失败 : '+res.getBody());
	            }


    	  	}

    	  	if(!cpList.isEmpty() && !ida.ToNC__c ){
    	  		String reuslt = ContractWebService.sycToNcNew(cpList);
    	  		ida.ResultMsg2__c = reuslt == null? null: (reuslt.length() > 255 ? reuslt.substring(0,254):reuslt);
    	  		ida.ToNC__c = true;
    	  	}

    	  	update ida;

    	  	msg = '同步成功!';


    	}catch (Exception e) {
    	    update ida;
    		msg = e.getMessage()+e.getStackTraceString();
    	}
    	isSuc = true;
    	


    }


    public class CKBean{
    	public String djh ;//单据号
    	public String djrq;//单据日期
    	public String store;//仓库
    	public String kuzz ;//库存组织
    	public String pkcorp;//公司
    	public String bm;//部门
    	public String sfswfh;//是否实物发货
    	public String ywy;//业务员
    	public String bz;//备注
    	public String pk_invbasdoc;//存货基本档案
    	public String pk_invmandoc;//存货管理档案
    	public String opertype;//单据状态 2:保存态
    	public String ywks ;//业务客商
    	public String sf_hid;
    	public String sf_bid;
    	public String h_sapply_hid;//上游单据表头ID
    	public String b_sapply_bid;//上游单据表体ID
    	public String phone;//联系电话
    	public String sffqxs;//是否分期销售
    	public String sfhxx ;//收发货信息
    	public Decimal sl ;//数量

    	public CKBean(ProductBean p){

    		djh = p.hhdh;
    		djrq = System.now().format('yyyy-MM-dd');
    		store = p.store;
    		kuzz = p.kuzz;
    		pkcorp = p.pkcorp;
    		bm = p.bm;
    		sfswfh = p.sfswfh;
    		ywy = p.ywy;
    		bz = p.bz;
    		pk_invbasdoc = p.pk_invbasdoc;
    		pk_invmandoc = p.pk_invmandoc;
    		opertype = p.opertype;
    		ywks = p.ywks;
    		sf_hid = p.sf_hid;
    		sf_bid = p.sf_bid;
    		h_sapply_hid = p.h_sapply_hid;
    		b_sapply_bid = p.b_sapply_bid;
    		phone = p.phone;
    		sffqxs = p.sffqxs;
    		sfhxx = p.sfhxx;
    		sl = p.sl_ck;

    	}


    }
    public class CKMBean{
    	public String djh ;//单据号
    	public String djrq;//单据日期
    	public String store;//仓库
    	public String kuzz ;//库存组织
    	public String pkcorp;//公司
    	public String bm;//部门
    	//public String sfswfh;//是否实物发货
    	public String ywy;//业务员
    	public String bz;//备注
    	public String pk_invbasdoc;//存货基本档案
    	public String pk_invmandoc;//存货管理档案
    	public String opertype;//单据状态 2:保存态
    	public String ywks ;//业务客商
    	public String sf_hid;
    	public String sf_bid;
    	public String h_sapply_hid;//上游单据表头ID
    	public String b_sapply_bid;//上游单据表体ID
    	public String phone;//联系电话
    	//public String sffqxs;//是否分期销售
    	public String sfhxx ;//收发货信息
    	public Decimal sl ;//数量

    	public CKMBean(ProductBean p){

    		djh = p.hhdh;
    		djrq = System.now().format('yyyy-MM-dd');
    		store = p.store;
    		kuzz = p.kuzz;
    		pkcorp = p.pkcorp;
    		bm = p.bm;
    		//sfswfh = p.sfswfh;
    		ywy = p.ywy;
    		bz = p.bz;
    		pk_invbasdoc = p.pk_invbasdoc;
    		pk_invmandoc = p.pk_invmandoc;
    		opertype = p.opertype;
    		ywks = p.ywks;
    		sf_hid = p.sf_hid;
    		sf_bid = p.sf_bid;
    		h_sapply_hid = p.h_sapply_hid;
    		b_sapply_bid = p.b_sapply_bid;
    		phone = p.phone;
    		//sffqxs = p.sffqxs;
    		sfhxx = p.sfhxx;
    		sl = p.sl_ck;

    	}


    }
    public class ProductBean{

    	public String name ;//产品名称
    	public String djh ;//单据号
    	public String djrq;//单据日期

    	public String store;//仓库
    	public String kuzz ;//库存组织
    	public String pkcorp;//公司

    	public String bm;//部门
    	public String sfswfh;//是否实物发货
    	public String ywy;//业务员
    	public String bz;//备注
    	public String pk_invbasdoc;//存货基本档案
    	public String pk_invmandoc;//存货管理档案
    	public String opertype;//单据状态 2:保存态
    	public String ywks ;//业务客商
    	public String sf_hid;
    	public String sf_bid;
    	public String h_sapply_hid;//上游单据表头ID
    	public String b_sapply_bid;//上游单据表体ID
    	public String phone;//联系电话
    	public String sffqxs;//是否分期销售
    	public String sfhxx ;//收发货信息
    	public Decimal sl ;//数量
    	public Decimal sl_ck ;//数量
    	public Decimal sl_sale ;//数量

    	public String hhdh ;//还回单号
    	public String ckdh;//出入库申请单
    	public Decimal price ;
    	public String nccode;

    	public String unitcode ;//公司编码
    	public String custcode ;//客户编码



    	public ProductBean(Map<String,Object> m ){
    		name = DataUtil.getStringValue(m.get('B_INVNAME'));

    		store = DataUtil.getStringValue(m.get('B_RECVMATERWHID'));
    		kuzz = DataUtil.getStringValue(m.get('H_PK_ORG_ID'));
    		pkcorp = DataUtil.getStringValue(m.get('H_PK_CORP'));

    		bm = DataUtil.getStringValue(m.get('H_CDPTID'));

    		sfswfh = DataUtil.getStringValue(m.get('H_PK_DEFDOC3'));
    		ywy = DataUtil.getStringValue(m.get('H_CBIZID'));


    		pk_invbasdoc = DataUtil.getStringValue(m.get('B_CINVBASID'));
    		pk_invmandoc = DataUtil.getStringValue(m.get('B_CINVENTORYID'));

    		opertype = '2';

    		ywks = DataUtil.getStringValue(m.get('H_PK_DEFDOC7'));

    		sf_hid = DataUtil.getStringValue(m.get('SF_HID'));
    		sf_bid = DataUtil.getStringValue(m.get('SF_BID'));

    		h_sapply_hid = DataUtil.getStringValue(m.get('H_SAPPLY_HID'));
    		b_sapply_bid = DataUtil.getStringValue(m.get('B_SAPPLY_BID'));

    		phone = DataUtil.getStringValue(m.get('H_VUSERDEF5'));

    		sffqxs = DataUtil.getStringValue(m.get('H_PK_DEFDOC9'));

    		sfhxx = DataUtil.getStringValue(m.get('H_PK_DEFDOC1'));
    		sl = DataUtil.getDecimalValue(m.get('HHSL'));
    		hhdh = DataUtil.getStringValue(m.get('HHDH'));
    		ckdh = DataUtil.getStringValue(m.get('H_VBILLCODE'));
    		nccode = DataUtil.getStringValue(m.get('B_INVCODE'));

    		custcode = DataUtil.getStringValue(m.get('H_CUSTCODE'));
    		unitcode = DataUtil.getStringValue(m.get('H_UNITCODE'));

    	}
    	public ProductBean(InstrumentDeliverynDetails__c idd ){

			hhdh = idd.ReturnNo__c ;
			sl= idd.ReturnQuantity__c ;
			sl_sale= idd.ResaleQuantity__c ;
			sl_ck = idd.FreeQuantity__c ;
			price = idd.NcPrice__c ;
			sf_bid = idd.SF_ID__c ;
			ckdh = idd.WarehouseNo__c ;
			nccode = idd.Code__c ;
			if(idd.RowData__c != null ){
				Map<String,Object> m  = (Map<String,Object> )JSON.deserializeUntyped(idd.RowData__c);

	    		name = DataUtil.getStringValue(m.get('name'));

	    		store = DataUtil.getStringValue(m.get('store'));
	    		kuzz = DataUtil.getStringValue(m.get('kuzz'));
	    		pkcorp = DataUtil.getStringValue(m.get('pkcorp'));

	    		bm = DataUtil.getStringValue(m.get('bm'));

	    		sfswfh = DataUtil.getStringValue(m.get('sfswfh'));
	    		ywy = DataUtil.getStringValue(m.get('ywy'));


	    		pk_invbasdoc = DataUtil.getStringValue(m.get('pk_invbasdoc'));
	    		pk_invmandoc = DataUtil.getStringValue(m.get('pk_invmandoc'));

	    		opertype = '2';

	    		ywks = DataUtil.getStringValue(m.get('ywks'));

	    		sf_hid = DataUtil.getStringValue(m.get('sf_hid'));

	    		h_sapply_hid = DataUtil.getStringValue(m.get('h_sapply_hid'));
	    		b_sapply_bid = DataUtil.getStringValue(m.get('b_sapply_bid'));

	    		phone = DataUtil.getStringValue(m.get('phone'));

	    		sffqxs = DataUtil.getStringValue(m.get('sffqxs'));

	    		sfhxx = DataUtil.getStringValue(m.get('sfhxx'));
	    		custcode = DataUtil.getStringValue(m.get('custcode'));
	    		unitcode = DataUtil.getStringValue(m.get('unitcode'));
			}
			
    		

    	}
   
    }








}